package com.sanjiayi.swagger;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

public class Swagger2Config {
    @Bean
    public Docket createRestApi(){

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()    //选择器
                //为当前包下controller生成API文档
                  .apis(RequestHandlerSelectors.basePackage("com.zt.controller"))
                //为有@Api注解的Controller生成API文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                //为有@ApiOperation注解的方法生成API文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();

    }


    //1.配置文档信息
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("用户服务文档")
                .description("用户服务文档的描述-谁用了干什么")
                .contact(new Contact("王卓煜，张磊，李家逸","","2210102150@qq.com"))
                .version("1.0")
                .build();
    }
}
